package mysgoog.util;

import java.io.*;
import java.util.*;

public class Lib
{
    private static boolean run = true;

    public static void log(String txt)
    {
        if (run)
            return;
        try
        {
            FileOutputStream fos = new FileOutputStream("BrownLog.txt", true);
            PrintStream ps = new PrintStream(fos);
            ps.println(txt);
            ps.flush();
            ps.close();
        }
        catch (FileNotFoundException e)
        {
            e.printStackTrace();
        }
    }

    private static Random random = new Random(0);
    public static PrintWriter log;
    static
    {
        try
        {
            log = new PrintWriter(new FileOutputStream("debug_log.txt"));
        }
        catch (FileNotFoundException e)
        {
            e.printStackTrace();
        }
    }

    public static int random(int range)
    {
        assertTrue(range > 0);
        return random.nextInt(range);
    }
    public static void debug(String s)
    {
        // System.out.println(s);
        log.println(s);
        log.flush();
    }
    public static void assertTrue(boolean expression)
    {
        if (!expression)
            throw new AssertionFailureError();
    }
    public static void assertTrue(boolean expression, String message)
    {
        if (!expression)
            throw new AssertionFailureError(message);
    }
    public static void assertNotReached()
    {
        assertTrue(false);
    }
    public static String fixLenInt(int num, int len)
    {
        String res = "" + num;
        while (res.length() < len)
            res = ' ' + res;
        return res;
    }
}

class AssertionFailureError extends Error
{
    private static final long serialVersionUID = 1L;

    AssertionFailureError()
    {
        super();
    }
    AssertionFailureError(String message)
    {
        super(message);
    }
}